package com.atguigu.gulimall.search.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author Yanglinfengkk
 * 自定义Session配置类
 */
@Configuration
public class GuliMallSessionConfig {

    /**
     * 设置Cookie信息   保证父域子域Session数据共享
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
        //设置Cookie的父域名
        cookieSerializer.setDomainName("gulimall.com");
        //设置Cookie名
        cookieSerializer.setCookieName("GULISESSION");
        return cookieSerializer;
    }

    /**
     * FastJson 转换redis格式
     * @return
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer(){
        return new GenericJackson2JsonRedisSerializer();
    }
}
